home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / MiscKit1.7.1 / MiscKit / Examples / MiscString / stest3.m < prev    next >
Encoding:
Text File  |  1995-04-12  |  2.5 KB  |  70 lines

  1. //        Written by Carl Lindberg Copyright (c) 1994 by Carl Lindberg.
  2. //                Version 1.0.  All rights reserved.
  3. //
  4. //        This notice may not be removed from this source code.
  5. //
  6. //    This program is included in the MiscKit by permission from the author
  7. //    and its use is governed by the MiscKit license, found in the file
  8. //    "LICENSE.rtf" in the MiscKit distribution.  Please refer to that file
  9. //    for a list of all applicable permissions and restrictions.
  10. //    
  11.  
  12. #import <appkit/appkit.h>
  13. #import "mscarl.h"
  14.  
  15.  
  16. #define NUMSTRINGS 1
  17. #define NUMSEARCHES 5
  18.  
  19. char *strs[NUMSTRINGS] = {
  20. "abcABCaBC456 HelloabcdHiabc",
  21. };
  22.  
  23. char *srchs[NUMSEARCHES] = {
  24. "abc",
  25. "ABC",
  26. "abcabc",
  27. NULL,
  28. "c45"
  29. };
  30.  
  31. void main()
  32. {
  33.   int i,j,k,l,m;
  34.   id str = [MiscString new];
  35.   id tmp;
  36.  
  37.   for (i=0;i<NUMSTRINGS;i++) {
  38.     printf("----------------------------------------------\n");
  39.     [str setStringValue:strs[i]];
  40.     printf("String now is: <%s>\n",strs[i]);
  41.     for (j=0;j<NUMSEARCHES;j++) {
  42.       printf("Num of '%s': %d  nocase: %d  nocase/overlap: %d\n",srchs[j],
  43.         [str numOf:srchs[j]],
  44.         [str numOf:srchs[j] caseSensitive:NO],
  45.         [str numOf:srchs[j] caseSensitive:NO overlap:YES]);
  46.         printf("Spots of '%s' nocase/overlap:",srchs[j]);
  47.         for (k=0;(l = [str spotOfStr:srchs[j] occurrenceNum:k caseSensitive:NO overlap:YES]) >=0;k++) printf(" %d",l);
  48.         printf("\nrSpots of '%s' nocase/overlap:",srchs[j]);
  49.         for (k=0;(l = [str rspotOfStr:srchs[j] occurrenceNum:k caseSensitive:NO overlap:YES]) >=0;k++) printf(" %d",l);
  50.         printf("\n");
  51.         for (k=-1;k<5;k++) printf("replace %dth '%s' with '[]': '%s'\n",
  52.           k,srchs[j],[[[str copy] replace:srchs[j] with:"[]" occurrenceNum:k caseSensitive:NO] stringValueAndFree]);
  53.         for (k=-1;k<5;k++) printf("overlap replace %dth '%s' with '[]': '%s'\n",
  54.           k,srchs[j],[[[str copy] replace:srchs[j] with:"[]" occurrenceNum:k caseSensitive:NO overlap:YES] stringValueAndFree]);
  55.         [(tmp = [str copy]) replaceEveryOccurrenceOf:srchs[j] with:"[]"];
  56.      printf("replace all '%s' with '[]': %s\n",srchs[j],
  57.       [tmp stringValueAndFree]);
  58.         [(tmp = [str copy]) replaceEveryOccurrenceOf:srchs[j] with:"[]" caseSensitive:NO];
  59.      printf("nocase replace all '%s' with '[]': %s\n",srchs[j],
  60.       [tmp stringValueAndFree]);
  61.         [(tmp = [str copy]) replaceEveryOccurrenceOf:srchs[j] with:"[]" caseSensitive:NO overlap:YES];
  62.      printf("nocase/overlap replace all '%s' with '[]': %s\n",srchs[j],
  63.       [tmp stringValueAndFree]);
  64.      }
  65.    }
  66.   [str free];
  67. }      
  68.  
  69.  
  70.